<%#
 Copyright 2013-2025 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
<%_ if (kubernetesUseDynamicStorage) { _%>
apiVersion: <%= KUBERNETES_CORE_API_VERSION %>
kind: PersistentVolumeClaim
metadata:
  name: <%= app.baseName.toLowerCase() %>-elasticsearch-pvc
  namespace: <%= kubernetesNamespace %>
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
  <%_ if (kubernetesStorageClassName) { _%>
  storageClassName: <%= kubernetesStorageClassName %>
  <%_ } _%>
---
<%_ } _%>
apiVersion: <%= KUBERNETES_DEPLOYMENT_API_VERSION %>
kind: Deployment
metadata:
  name: <%= app.baseName.toLowerCase() %>-elasticsearch
  namespace: <%= kubernetesNamespace %>
spec:
  replicas: 1
  selector:
    matchLabels:
      app: <%= app.baseName.toLowerCase() %>-elasticsearch
  template:
    metadata:
      labels:
        app: <%= app.baseName.toLowerCase() %>-elasticsearch
<%_ if (istio) { _%>
      annotations:
        sidecar.istio.io/inject: "false"
<%_ } _%>
    spec:
      securityContext:
        fsGroup: 1000
      volumes:
      - name: data
<%_ if (kubernetesUseDynamicStorage) { _%>
        persistentVolumeClaim:
          claimName: <%= app.baseName.toLowerCase() %>-elasticsearch-pvc
<%_ } else { _%>
        emptyDir: {}
<%_ } _%>
      initContainers:
      - name: init-sysctl
        image: busybox
        command:
        - sysctl
        - -w
        - vm.max_map_count=262144
        securityContext:
          privileged: true
      containers:
      - name: elasticsearch
        image: <%- dockerContainers.elasticsearch %>
        env:
        - name: discovery.type
          value: single-node
        ports:
        - containerPort: 9200
          name: http
          protocol: TCP
        - containerPort: 9300
          name: transport
          protocol: TCP
        volumeMounts:
        - name: data
          mountPath: /usr/share/elasticsearch/data/
        resources:
          requests:
            memory: "512Mi"
            cpu: "500m"
          limits:
            memory: "2Gi"
            cpu: "1"
---
apiVersion: <%= KUBERNETES_CORE_API_VERSION %>
kind: Service
metadata:
  name: <%= app.baseName.toLowerCase() %>-elasticsearch
  namespace: <%= kubernetesNamespace %>
spec:
  selector:
    app: <%= app.baseName.toLowerCase() %>-elasticsearch
  ports:
  - port: 9200
    name: http
    protocol: TCP
  - port: 9300
    name: transport
    protocol: TCP
